import fcntl
import logging
from kvm_x86_types import *

class KVM:
    def __init__(self):
        pass

    def has_capability(self, kvm_fd, cap):
        """
        Determines if the KVM implementation has the requested capability.
        :return A non-zero value if the capability is supported.
        """
        ret = 0

        try:
            ret = fcntl.ioctl(kvm_fd, KVM_CHECK_EXTENSION, cap)
        except Exception:
            logger.debug('KVM_CHECK_EXTENSION failed')
        finally:
            logger.info('%s: %d', cap, ret)

        return ret

